//
//  UIView+ZXAlignmentRectInsets.m
//  YiShangbao
//
//  Created by simon on 2018/6/27.
//  Copyright © 2018年 com.Microants. All rights reserved.
//

#import "UIView+ZXAlignmentRectInsets.h"
#import "NSObject+ZXRuntime.h"

static const char *uiView_kRectInsetsChar = "uiView_kRectInsetsChar";

@implementation UIView (ZXAlignmentRectInsets)


- (void)setRectInsets:(UIEdgeInsets)rectInsets
{
    NSValue *value = [NSValue valueWithUIEdgeInsets:rectInsets];
    objc_setAssociatedObject(self, &uiView_kRectInsetsChar, value, OBJC_ASSOCIATION_COPY_NONATOMIC);

}
- (UIEdgeInsets)rectInsets
{
    NSValue *value = objc_getAssociatedObject(self, &uiView_kRectInsetsChar);
    return value.UIEdgeInsetsValue;
}


+ (void)load
{
    [self zx_exchangeInstanceMethodWithOriginalSelector:@selector(alignmentRectInsets) swizzledSelector:@selector(zx_alignmentRectInsets)];
}

- (UIEdgeInsets)zx_alignmentRectInsets
{
    if (!UIEdgeInsetsEqualToEdgeInsets(self.rectInsets, UIEdgeInsetsZero))
    {
        return self.rectInsets;
    }
    return  [self zx_alignmentRectInsets];
}

@end
